//
//  DealModel.m

#import "DealModel.h"


@implementation DealModel

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    
    DealModel *model = [[DealModel alloc] init];
    model.deal_id = dict[@"deal_id"];
    model.title = dict[@"title"];
    model.desc = dict[@"description"];
    model.list_price = [dict[@"list_price"] doubleValue];
    model.current_price = [dict[@"current_price"] doubleValue];
    model.categories = dict[@"categories"];
    model.purchase_count = [dict[@"purchase_count"] doubleValue];
    model.purchase_deadline = dict[@"purchase_deadline"];
    model.publish_date = dict[@"publish_date"];
    model.image_url = dict[@"image_url"];
    model.s_image_url = dict[@"s_image_url"];
    model.deal_h5_url = dict[@"deal_h5_url"];
    
    //其他商区
    NSMutableArray *tempArray = [NSMutableArray array];
    NSArray *array = dict[@"businesses"];
    if (array.count>0) {
        for (NSDictionary *dict in array) {
            BusinessModel *model = [[BusinessModel alloc] initWithDictionary:dict];
            
            [tempArray addObject:model];
        }
        model.businesses = tempArray;
    }
    
    model.details = dict[@"details"];
    model.notice = dict[@"notice"];
    
    //约束
    if (dict[@"restrictions"]) {
        model.restrictions = [[RestrictionModel alloc] initWithDictionary:dict[@"restrictions"]];
    }
    
    
    return model;
}


- (void)setList_price:(double)list_price
{
    _list_price = list_price;
    
    _list_price_text = [NSString stringWithDouble:list_price fractionCount:2];
}

- (void)setCurrent_price:(double)current_price
{
    _current_price = current_price;
    
    _current_price_text = [NSString stringWithDouble:current_price fractionCount:2];
}


@end




